package com.indeep.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.indeep.user.mapper.po.AppFollowPO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AppFollowMapper extends BaseMapper<AppFollowPO> {
//
//    @Select("SELECT u.id AS ydUserId, u.username, u.avatar AS photo " +
//            "FROM app_user u " +
//            "INNER JOIN ( " +
//            "    SELECT follow_user_id " +
//            "    FROM app_follow " +
//            "    WHERE user_id = #{userId} AND status = 1 " +
//            "    ORDER BY update_time DESC " +
//            "    LIMIT #{startIndex}, #{pageSize} " +
//            ") f ON u.id = f.follow_user_id")
//    List<User4BO> listFollow(@Param("userId") Long userId,
//                             @Param("startIndex") Integer startIndex,
//                             @Param("pageSize") Integer pageSize);
//
//    @Select("select follow_user_id " +
//            "from app_follow " +
//            "where user_id = #{userId} and status = 1")
//    List<Long> listAllFollow(@Param("userId") Long userId);
//
//    @Select("select user_id " +
//            "from app_follow " +
//            "where follow_user_id = #{userId} and status = 1")
//    List<Long> listAllFans(@Param("userId") Long userId);
//
//    @Select("SELECT u.id AS ydUserId, u.username, u.avatar AS photo " +
//            "FROM app_user u " +
//            "INNER JOIN ( " +
//            "    SELECT user_id " +
//            "    FROM app_follow " +
//            "    WHERE follow_user_id = #{userId} AND status = 1 " +
//            "    ORDER BY update_time DESC " +
//            "    LIMIT #{startIndex}, #{pageSize} " +
//            ") f ON u.id = f.user_id")
//    List<User4BO> listFans(@Param("userId") Long userId,
//                           @Param("startIndex") Integer startIndex,
//                           @Param("pageSize") Integer pageSize);
//
//
//    //推荐四名粉丝多的人
//    @Select("select id ydUserId,username,avatar photo from app_user where " +
//            "id !=#{userId} and id not in (select follow_user_id from app_follow where user_id = #{userId} and status= 1 ) " +
//            "order by fans desc limit 4 ")
//    List<User4BO> selectFansBig(Long userId);
//
//    // 模糊查询关注列表
//    @Select("select id ydUserId, username, avatar photo, 'true' isFollowed " +
//            "from app_user " +
//            "where id in (select follow_user_id " +
//            "             from app_follow " +
//            "             where user_id = #{userId} " +
//            "               and status = 1 " +
//            ")" +
//            "  and username like concat('%', #{username}, '%')")
//    List<User4BO> findFollowDataNoClear(@Param("userId") Long userId, @Param("username") String username);
//
//    // 模糊查询粉丝列表
//    @Select("<script>" +
//            "SELECT yu.id ydUserId,yu.username ,yu.avatar photo " +
//            "FROM app_follow yf " +
//            "  left join app_user yu on yf.user_id = yu.id " +
//            "where yf.status = 1 " +
//            "  and yf.follow_user_id = #{userId}" +
//            "  <if test = \"username != null\"> and yu.username like concat('%',#{username},'%')</if>" +
//            "</script>")
//    List<User4BO> findFansDataNoClear(@Param("userId") Long userId, @Param("username") String username);
//
//    // 移除粉丝或关注(后台管理)
//    @Update("<script>" +
//            "update app_follow set status = 0 " +
//            "<if test='type == 1'> where user_id=#{id} and follow_user_id=#{removeId} </if>" +
//            "<if test='type == 2'> where user_id=#{removeId} and follow_user_id=#{id} </if>" +
//            "</script>")
//    Integer removeFollowOrFans(IdRemoveDTO idRemoveDto);
//
//    /**
//     * 查询两个用户中是否互相关注
//     *
//     * @param u1 用户1的ID
//     * @param u2 用户2的ID
//     * @return 关注记录数，2则代表互相关注
//     */
//    @Select("select count(*) from app_follow " +
//            "where (user_id = #{u1} and follow_user_id = #{u2} and status = 1)" +
//            "   or (user_id = #{u2} and follow_user_id = #{u1} and status = 1)")
//    Integer selectFollowEach(@Param("u1") Long u1, @Param("u2") Long u2);
//
//    @Insert({
//            "<script>",
//            "INSERT INTO app_follow (user_id, follow_user_id, status) VALUES ",
//            "<foreach collection='longList' item='userId' index='index' separator=','>"+
//                    "(#{userId}, #{id}, 1)"+
//                    "</foreach> ",
//            "ON DUPLICATE KEY UPDATE status = CASE WHEN status = 0 THEN 1 ELSE 0 END",
//            "</script>"
//    })
//    Integer insertFansByPushHand(@Param("longList") List<Long> longList, @Param("id") Long id);

}
